using System;
using System.Xml;
using UnityEngine;

namespace AssemblyCSharp
{
	public class StarDAO : XmlParserDAO, CommonDAOIF<StarDomain>
	{
		private StarDomain mStarDomain = null;
		
		public bool readStarXml(String xmlString)
		{
			return mXmlParser.readXmlString(xmlString);
		}
		
		public override System.Object parse()
		{
			try
			{
				String returnValue = "";
				mStarDomain = new StarDomain();
				
				foreach(XmlNode item in mXmlParser.xmlDoc.ChildNodes)
				{
					GetChildren(item);
				}
				
				return returnValue;
			}
			catch ( Exception e )
			{
				Debug.Log( e.ToString());
				return null;
			}
		}

		private PlanetDAO mPlanetDAO = new PlanetDAO();
		private void GetChildren(XmlNode node)
		{
			if (node.LocalName == Constant.StarPlanet) {
				// Call Planet DAO
				mPlanetDAO.readStarXml(node.OuterXml);
				mPlanetDAO.parse();
				PlanetDomain mPlanetDomain = mPlanetDAO.getDomain();
				mStarDomain.setPlanet(mPlanetDomain.Name, mPlanetDomain);
			} else if (node.LocalName == Constant.StarName) {
				mStarDomain.Name = node.InnerText;
			} else if (node.LocalName == Constant.StarRadious) {
				mStarDomain.Radius = Convert.ToInt32(node.InnerText);
			}
			else
			{
				foreach (XmlNode item in node.ChildNodes)
				{
					GetChildren(item);
				}
			}
		}
		
		public StarDomain getDomain ()
		{
			return mStarDomain;
		}
	}
}

